/*
 * @Date: 2024-07-30 15:29:14
 * @Author: LiSong
 * @LastEditors: LiSong
 * @LastEditTime: 2025-02-13 14:07:21
 * @Description: 
 */
import XEUtils from 'xe-utils';
import { defAxios as request } from '@/utils/http';
import { columns } from '@/mock/DataTableMockData';
// 表格请求API
export const useTableApi = req => {
  return {
    /**
     * 解析SQL信息
     * 
     * @param {String} content SQL数据
     * @returns axios
     */
    analyseSQL: function (content) {
      const reqAxios = req || request;
      return reqAxios({
        url: '/data/parse',
        method: 'POST',
        data: {
          content,
        },
      });
      // const fieldList = XEUtils.toTreeArray(columns).map(item => {
      //   return item.field;
      // });
      // return new Promise(resolve => {
      //   resolve({
      //     msg: '业务成功',
      //     code: 200,
      //     data: {
      //       fieldList: fieldList,
      //       paramList: ['adCode', 'agCode']
      //     },
      //   });
      // });
    },
    /**
     * 执行SQL信息
     * @param {String} content SQL数据
     * @returns axios
     */
    executeSQL: function (content) {
      const reqAxios = req || request;
      return reqAxios({
        url: '/data/execute',
        method: 'POST',
        data: {
          tableId: content,
          busiType: 'ET002'
        },
      });
    },
    /**
     * 解析请求接口
     * @param {Object} options 请求配置
     * @returns 
     */
    analyseReq: function (options) {
      const reqAxios = req || request;
      // return reqAxios({
      //   ...options
      // });
      const fieldList = XEUtils.toTreeArray(columns).map(item => {
        return {
          field: item.field,
          title: item.title,
        };
      });
      return new Promise(resolve => {
        resolve({
          data: fieldList,
        });
      });
    },
  };
};
